<template>
  <div class="index_view">
    <div class="row1_view">
      <div class="title">HELLO，你好</div>
      <div class="sub_title">欢迎来到陪跑尽调后台管理系统</div>
    </div>

    <div class="row2_div">
      <div class="row2_left_view">
        <div class="r1_view">
          <div class="l_title">数据统计</div>
          <div class="r_title" @click="mouthselect_click">
            2021年10月-{{ mouth_value[1] }}
            <i
              class="el-icon-arrow-down"
              style="font-size: 20px; font-weight: 600; margin-left: 10px"
            ></i>
            <div class="picker_container">
              <el-date-picker
                key="datePickerKey"
                v-model="mouth_value"
                ref="datePickerRef"
                type="monthrange"
                align="right"
                unlink-panels
                range-separator="至"
                start-placeholder="开始月份"
                end-placeholder="结束月份"
                :picker-options="pickerOptions"
                value-format="yyyy-MM"
              >
              </el-date-picker>
            </div>
          </div>
        </div>
        <div class="r2_view">
          <div class="r2_item">
            <div class="name">客户总数</div>
            <div class="sub_name">12</div>
          </div>
          <div class="r2_item">
            <div class="name">客户总数</div>
            <div class="sub_name">12</div>
          </div>
          <div class="r2_item">
            <div class="name">客户总数</div>
            <div class="sub_name">12</div>
          </div>
          <div class="r2_item">
            <div class="name">客户总数</div>
            <div class="sub_name">12</div>
          </div>
        </div>
      </div>
      <div class="row2_right_view">
        <div class="r1_view_day">
          <div class="l_title_day">最新动态</div>
          <div class="r_title_day" @click="dayselect_click">
            {{ day_value }}
            <i
              class="el-icon-arrow-down"
              style="font-size: 20px; font-weight: 600; margin-left: 10px"
            ></i>
            <div class="picker_container_day">
              <el-date-picker
                key="daydatePickerKey"
                v-model="day_value"
                align="left"
                type="date"
                ref="daydatePickerRef"
                :picker-options="dayPickerOptions"
                value-format="yyyy-MM"
              >
              </el-date-picker>
            </div>
          </div>
        </div>
        <div class="r2_view_day">
          <div class="row2_item">
            <div class="tag"></div>
            <div class="time">10：55</div>
            <div class="cont">黄小文通过扫描添加了新客户沐白</div>
          </div>
        </div>
      </div>
    </div>

    <div class="row3_div">
      <div class="select_div">
        <div class="category_div">
          <div
            @click="category_click(k)"
            :class="['c_item', k === category_active && 'active']"
            v-for="(v, k) in category_list"
            :key="k"
          >
            {{ v }}
          </div>
        </div>
        <div class="time_div">
          <div :class="['t_item', time_index === 0 && 'active']" @click="time_click(0)">
            今日
          </div>
          <div :class="['t_item', time_index === 1 && 'active']" @click="time_click(1)">
            近7天
          </div>
          <div :class="['t_item', time_index === 2 && 'active']" @click="time_click(2)">
            近30天
          </div>
          <div :class="['t_item', time_index === 3 && 'active']" @click="time_click(3)">
            近1年
          </div>
          <div
            :class="['time_item', time_index === 4 && 'active']"
            @click="time_click(4)"
          >
            <i
              class="el-icon-date"
              style="margin-right: 10px; color: #0084ff; font-size: 18px"
            ></i>
            2022-12-12 至 2023-01-05
            <div class="time_select_div">
              <el-date-picker
                v-model="time_value"
                type="daterange"
                align="right"
                unlink-panels
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :picker-options="timePickerOptions"
                ref="timedatePickerRef"
              ></el-date-picker>
            </div>
          </div>
        </div>
      </div>
      <div class="echart_div">
        <echart ref="index"></echart>
      </div>
    </div>
  </div>
</template>

<script>
import echart from "@/components/echarts/echarts_init.vue";
export default {
  components: {
    echart,
  },
  data() {
    const pickerOptions = {
      shortcuts: [
        {
          text: "本月",
          onClick(picker) {
            picker.$emit("pick", [new Date(), new Date()]);
          },
        },
        {
          text: "今年至今",
          onClick(picker) {
            const end = new Date();
            const start = new Date(new Date().getFullYear(), 0);
            picker.$emit("pick", [start, end]);
          },
        },
        {
          text: "最近六个月",
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setMonth(start.getMonth() - 6);
            picker.$emit("pick", [start, end]);
          },
        },
      ],
    };
    const dayPickerOptions = {
      disabledDate(time) {
        return time.getTime() > Date.now();
      },
      shortcuts: [
        {
          text: "今天",
          onClick(picker) {
            picker.$emit("pick", new Date());
          },
        },
        {
          text: "昨天",
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit("pick", date);
          },
        },
        {
          text: "一周前",
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit("pick", date);
          },
        },
      ],
    };
    const timePickerOptions = {
      shortcuts: [
        {
          text: "最近一周",
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit("pick", [start, end]);
          },
        },
        {
          text: "最近一个月",
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit("pick", [start, end]);
          },
        },
        {
          text: "最近三个月",
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit("pick", [start, end]);
          },
        },
      ],
    };
    const day_init = () => {
      const date = new Date();
      return date.toISOString().split("T")[0]; // 返回格式为 YYYY-MM-DD
    };
    return {
      pickerOptions,
      mouth_value: [],
      day_value: day_init(),
      dayPickerOptions,
      category_list: ["新增客户数", "新增报告数", "陪跑活跃度"],
      category_active: 0,
      timePickerOptions,
      time_value: [],
      time_index: 0,
    };
  },
  mounted() {
    this.get_echart_data();
  },
  methods: {
    get_echart_data() {
      this.$refs.index.initChart('index', []);
    },

    mouthselect_click() {
      this.$refs.datePickerRef.focus();
    },
    dayselect_click() {
      this.$refs.daydatePickerRef.focus();
    },
    category_click(k) {
      this.category_active = k;
    },
    time_click(index) {
      this.time_index = index;
      if (index === 4) {
        this.$refs.timedatePickerRef.focus();
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.index_view {
  display: flex;
  flex-direction: column;
  min-width: 1200px;
  overflow-x: auto;
  .row1_view {
    width: 100%;
    height: 240px;
    background-image: url("../../assets/images/index_bg1.png");
    background-size: cover;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    .title {
      font-family: Microsoft YaHei;
      font-weight: bold;
      font-size: 32px;
      color: #314257;
      padding-left: 65px;
    }
    .sub_title {
      font-family: Microsoft YaHei;
      font-weight: 400;
      font-size: 22px;
      color: #0084ff;
      padding-left: 65px;
    }
  }
  .row2_div {
    width: 100%;
    height: 257px;
    display: flex;
    justify-content: space-between;
    margin-top: 15px;
    .row2_left_view {
      width: 57%;
      height: 257px;
      padding: 15px 20px;
      background: linear-gradient(0deg, #f9fafe 0%, #ffffff 100%);
      box-shadow: 0px 2px 8px 0px rgba(54, 131, 255, 0.1);
      border-radius: 12px;
      border: 2px solid #ffffff;
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      .r1_view {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        .l_title {
          font-family: Microsoft YaHei;
          font-weight: 400;
          font-size: 16px;
          color: #000000;
        }
        .r_title {
          font-family: Microsoft YaHei;
          font-weight: 400;
          font-size: 14px;
          color: #93a0af;
          position: relative;
          cursor: pointer;
          display: flex;
          align-items: center;
          .picker_container {
            position: absolute;
            right: 0;
            top: 0;
            width: 200px;
            height: 30px;
            display: flex;
            align-items: center;
            visibility: hidden;
          }
        }
      }
      .r2_view {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: repeat(2, 90px);
        grid-gap: 10px 25px;
        margin-top: 15px;
        .r2_item {
          display: flex;
          flex-direction: column;
          justify-content: space-evenly;
          background: #f0f3fa;
          .name {
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 14px;
            color: #4d5867;
            padding-left: 25px;
          }
          .sub_name {
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 20px;
            color: #000000;
            padding-left: 25px;
          }
        }
      }
    }
    .row2_right_view {
      width: calc(100% - 57% - 20px);
      height: 257px;
      background: linear-gradient(0deg, #f9fafe 0%, #ffffff 100%);
      box-shadow: 0px 2px 8px 0px rgba(54, 131, 255, 0.1);
      border-radius: 12px;
      border: 2px solid #ffffff;
      box-sizing: border-box;
      padding: 15px 20px;
      .r1_view_day {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        .l_title_day {
          font-family: Microsoft YaHei;
          font-weight: 400;
          font-size: 16px;
          color: #000000;
        }
        .r_title_day {
          font-family: Microsoft YaHei;
          font-weight: 400;
          font-size: 14px;
          color: #93a0af;
          position: relative;
          cursor: pointer;
          display: flex;
          align-items: center;
          .picker_container_day {
            position: absolute;
            left: 0;
            top: 0;
            width: 0px;
            height: 0px;
            display: flex;
            align-items: center;
            z-index: 0;
            overflow: hidden;
          }
        }
      }
      .r2_view_day {
        display: flex;
        flex-direction: column;
        .row2_item {
          display: flex;
          align-items: center;
          margin-top: 30px;
          .tag {
            width: 10px;
            height: 10px;
            background: #0084ff;
            border-radius: 50%;
          }
          .time {
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 14px;
            color: #93a0af;
            margin: 0 10px 0 20px;
          }
          .cont {
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 14px;
            color: #000000;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            overflow: hidden;
          }
        }
      }
    }
  }

  .row3_div {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 299px;
    background: linear-gradient(0deg, #f9fafe 0%, #ffffff 100%);
    box-shadow: 0px 2px 8px 0px rgba(54, 131, 255, 0.1);
    border-radius: 12px;
    border: 2px solid #ffffff;
    box-sizing: border-box;
    margin-top: 15px;
    padding: 15px 20px;
    .select_div {
      display: flex;
      align-items: center;
      justify-content: space-between;
      .category_div {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        grid-column-gap: 30px;
        .c_item {
          font-family: Source Han Sans CN;
          font-weight: 400;
          font-size: 16px;
          color: #93a0af;
          cursor: pointer;
          transition: all 0.3s;
          &.active {
            color: black !important;
          }
        }
      }
      .time_div {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr 1fr 3fr;
        grid-column-gap: 30px;
        .t_item {
          font-family: Source Han Sans CN;
          font-weight: 400;
          font-size: 12px;
          color: #93a0af;
          padding: 6px 10px;
          border-radius: 4px;
          border: 1px solid transparent;
          box-sizing: border-box;
          cursor: pointer;
          display: flex;
          align-items: center;
          justify-content: center;
          transition: all 0.3s;
          &.active {
            border: 1px solid #0084ff;
          }
        }
        .time_item {
          position: relative;
          width: 202px;
          height: 32px;
          border-radius: 4px;
          border: 1px solid #e8ecef;
          box-sizing: border-box;
          font-family: Source Han Sans CN;
          font-weight: 400;
          font-size: 12px;
          color: #93a0af;
          display: flex;
          align-items: center;
          justify-content: center;
          cursor: pointer;
          &.active {
            border: 1px solid #0084ff;
          }

          .time_select_div {
            position: absolute;
            right: 0;
            top: 0;
            width: 200px;
            height: 30px;
            display: flex;
            align-items: center;
            visibility: hidden;
          }
        }
      }
    }
    .echart_div {
      flex: 1;
    }
  }
}
</style>
